<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>订单列表</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
	* {
		font-size: 11pt;
	}
	div {
		border: solid 2px rgb(78,78,78);
		width: 75px;
		height: 75px;
		text-align: center;
	}
	li {
		margin: 10px;
	}
</style>
	  <script type="text/javascript" src="/adminjsps/js/jquery-3.2.1.min.js"></script>
  </head>
  
  <body style="background: rgb(254,238,189);">
<h1>我的订单</h1>

<table border="1" width="100%" cellspacing="0" background="black" id="table">
	<%--<tr bgcolor="rgb(78,78,78)" bordercolor="rgb(78,78,78)" style="color: white;">--%>
		<%--<td colspan="6">--%>
			<%--订单：8691b4150a0641e7a8729fd5e668820c　成交时间：2013-06-04 15:56:53　金额：<font color="red"><b>126.4</b></font>	已收货（完成）--%>
		<%--</td>--%>
	<%--</tr>--%>
	<%--<tr bordercolor="rgb(78,78,78)" align="center">--%>
		<%--<td width="15%">--%>
			<%--<div><img src="<c:url value='../book_img/20385925-1_l.jpg'/>" height="75"/></div>--%>
		<%--</td>--%>
		<%--<td>书名：Struts2深入详解</td>--%>
		<%--<td>单价：63.2元</td>--%>
		<%--<td>作者：孙鑫</td>--%>
		<%--<td>数量：2</td>--%>
		<%--<td>小计：126.4元</td>--%>
	<%--</tr>--%>
</table>
<script>
	window.onload=function () {
		$.ajax({
			url:"/allorder",
			type:"get",
			success:function (re) {
				console.log(re);
				if (re.code == 1000) {
					for (var i = 0; i < re.orders.length; i++) {
						if (re.orders[i].state != 2) {
							$("<tr bgcolor=\"rgb(78,78,78)\" bordercolor=\"rgb(78,78,78)\" style=\"color: white;\">\n" +
									"\t\t<td colspan=\"6\">\n" +
									"\t\t\t订单："+re.orders[i].oid+"　成交时间："+re.orders[i].ordertime+"　金额：<font color=\"red\"><b>"+re.orders[i].total+"</b></font>\t"+re.orders[i].stringstate+"\n" +
									"\t\t</td>\n" +
									"\t</tr>").appendTo("#table")
							for (var k = 0; k < re.orderitem.length; k++) {
								if (re.orderitem[k].oid == re.orders[i].oid) {
									$("<tr bordercolor=\"rgb(78,78,78)\" align=\"center\">\n" +
											"\t\t<td width=\"15%\">\n" +
											"\t\t\t<div><img src='"+re.orderitem[k].image+"' height=\"75\"/></div>\n" +
											"\t\t</td>\n" +
											"\t\t<td>书名："+re.orderitem[k].bname+"</td>\n" +
											"\t\t<td>单价："+re.orderitem[k].price+"元</td>\n" +
											"\t\t<td>作者："+re.orderitem[k].author+"</td>\n" +
											"\t\t<td>数量："+re.orderitem[k].count+"</td>\n" +
											"\t\t<td>小计："+re.orderitem[k].subtotal+"元</td>\n" +
											"\t</tr>").appendTo("#table")
								}
							}
						}else {
							$("<tr bgcolor=\"rgb(78,78,78)\" bordercolor=\"rgb(78,78,78)\" style=\"color: white;\">\n" +
									"\t\t<td colspan=\"6\">\n" +
									"\t\t\t订单："+re.orders[i].oid+"　成交时间："+re.orders[i].ordertime+"　金额：<font color=\"red\"><b>"+re.orders[i].total+"</b></font>\t<a id='state' name='"+re.orders[i].oid+"'>"+re.orders[i].stringstate+"</a>\n" +
									"\t\t</td>\n" +
									"\t</tr>").appendTo("#table")
							for (var k = 0; k < re.orderitem.length; k++) {
								if (re.orderitem[k].oid == re.orders[i].oid) {
									$("<tr bordercolor=\"rgb(78,78,78)\" align=\"center\">\n" +
											"\t\t<td width=\"15%\">\n" +
											"\t\t\t<div><img src='"+re.orderitem[k].image+"' height=\"75\"/></div>\n" +
											"\t\t</td>\n" +
											"\t\t<td>书名："+re.orderitem[k].bname+"</td>\n" +
											"\t\t<td>单价："+re.orderitem[k].price+"元</td>\n" +
											"\t\t<td>作者："+re.orderitem[k].author+"</td>\n" +
											"\t\t<td>数量："+re.orderitem[k].count+"</td>\n" +
											"\t\t<td>小计："+re.orderitem[k].subtotal+"元</td>\n" +
											"\t</tr>").appendTo("#table")
								}
							}
						}

					}
				}
			}
		})
	}
	$("#table").on("click","#state",function () {
		var a= $(this)
		var oid = $(this).attr('name');
		$.ajax({
			url:"/buyorders",
			type:"get",
			data:{
				oid:oid,
				newstate:3
			},
			success:function (re) {
				if (re.code == 1003) {
					location.href="/Home/Login.html";
				}else if (re.code == 1001) {
					console.log("修改失败")
				}else if (re.code == 1000) {
					a.html("已发货")
				}
			}
		})
	})
</script>
  </body>
</html>
